package com.redribbon.droidnoise;

import java.util.ArrayList;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteCallbackList;

public class StreamServer extends Service {

    /**
     * This is a list of callbacks that have been registered with the
     * service.  Note that this is package scoped (instead of private) so
     * that it can be accessed more efficiently from inner classes.
     */
    final RemoteCallbackList<StreamServerServiceCallback> mCallbacks = new RemoteCallbackList<StreamServerServiceCallback>();
    ArrayList<SongContainer> songs;
    ReadMedia reader;
	    
    @Override
    public void onCreate() {
    	songs = NoiseConstants.songs_to_stream;
    	passSongs();
    }
    
    private void passSongs() {
    	reader = new ReadMedia();
    	reader.pushFiles(songs);
    }
    
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return mBinder;
	}
	
	public void onDestroy() {
		reader.stopEverything();
	}

    /**
     * The StreamServerService is defined through IDL
     */
    private final StreamServerService.Stub mBinder = new StreamServerService.Stub() {
        public void registerCallback(StreamServerServiceCallback cb) {
            if (cb != null) mCallbacks.register(cb);
        }
        public void unregisterCallback(StreamServerServiceCallback cb) {
            if (cb != null) mCallbacks.unregister(cb);
        }
    };
	
    /**
     * Show a notification while this service is running.
     */
    /*private void showNotification() {
        // In this sample, we'll use the same text for the ticker and the expanded notification
        CharSequence text = getText(R.string.remote_service_started);

        // Set the icon, scrolling text and timestamp
        Notification notification = new Notification(R.drawable.audioicon, text, System.currentTimeMillis());

        // The PendingIntent to launch our activity if the user selects this notification
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, DroidNoise.class), 0);

        // Set the info for the views that show in the notification panel.
        notification.setLatestEventInfo(this, getText(R.string.remote_service_label),
                       text, contentIntent);

        // Send the notification.
        // We use a string id because it is a unique number.  We use it later to cancel.
        mNM.notify(R.string.remote_service_started, notification);
    }*/
    
}
